import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {CommentService, CommentType} from "../../../services/common/Comments";
import {JsonPipe} from "@angular/common";
import {StudyShareModule} from "../../StudyShareModule";

@Component({
  selector: 'app-comment',
  standalone: true,
  imports: [StudyShareModule, JsonPipe],
  templateUrl: './comment-detail.component.html',
  styleUrls: []
})
export class CommentDetailComponent implements OnInit {

  comment: CommentType | undefined;

  constructor(private route: ActivatedRoute, private commentService: CommentService) {
  }

  ngOnInit(): void {
    // this.route.params.subscribe(res => console.log(res));

    console.log(this.route.snapshot);
    // console.log(this.route.snapshot.queryParams['id']);
    if (!this.comment) {
      this.comment = this.commentService.getComment2(this.route.snapshot.queryParams['id']);
    }

    this.route.params.subscribe(res => console.log(res));
    this.route.paramMap.subscribe(res => console.log(res));
    if (!this.comment) {
      this.route.params.subscribe((res: any) => {
        this.comment = this.commentService.getComment2(res.id);
      });
    }


    /* var observable = this.route.paramMap.pipe(switchMap(paramMap => {
       let id: string | number|null = paramMap.get("id");
       console.log("id = ", id)
       if (id) {
         return Observable.create(this.commentServer.getFirstComment());
       }
       return Observable.create(null);
     }));*/

    /* observable.subscribe(comment => {
       console.log(comment);
     })*/
  }

  onChange() {
    console.log(JSON.stringify(this.comment))
  }
}
